﻿Imports Microsoft.Office.Interop.Word

Public Class Document


    Private abschnitte() As Paragraph 'kann sowohl ein Abschnitt mit Sätzen sein, als auch Sonderzeichen für Absatz o.ä.

End Class

Public Class Paragraph

    Private sentences() As Sentence
    Public Property empty() As Boolean
End Class

Public Class Sentence

    Public words() As String
    Private Property commonFormat() As MyFormat
    Public specialFormat() As MyFormat

End Class


Public Class MyFormat

    Public Property bold() As Boolean
    Public Property italic() As Boolean
    Public Property underlined() As Boolean
    Public Property size() As Integer
    Public Property font() As String
End Class


Public Class ThisAddIn

    Private Sub ThisAddIn_Startup() Handles Me.Startup


    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

    Private Sub Application_DocumentBeforeSave(ByVal Doc As Word.Document, ByRef SaveAsUI As Boolean, _
    ByRef Cancel As Boolean) Handles Application.DocumentBeforeSave
        Dim numOfParagraphs As Integer = Doc.Paragraphs.Count()

        For x As Integer = 1 To numOfParagraphs
            'Doc.Paragraphs(x).Range.InsertParagraphAfter()
            Dim ausgabe As String = ""
            'Dim wordCounter As Integer = 0

            Dim sentences As Sentences = Doc.Paragraphs(x).Range.Sentences
            For y As Integer = 0 To sentences.Count
                If y = 0 Then
                    Continue For
                End If
                Dim words = sentences(y).Words
                For z As Integer = 1 To words.Count
                    Dim text As String = words(z).Text
                    Dim zeichenString = text.Substring(0, 1)
                    Dim zeichenInt As Integer = AscW(text.Substring(0, 1))
                    ausgabe &= zeichenInt.ToString
                    ausgabe &= "|"
                    'Dim ausgabe As String = zeichenInt.ToString
                    'Doc.Paragraphs(x).Range.Text = ausgabe
                Next
            Next

            'ausgabe &= " __This is the end of paragraph "
            'ausgabe &= x
            'ausgabe &= ". It had "
            'ausgabe &= sentences.Count.ToString
            'ausgabe &= " sentences and "
            'ausgabe &= wordCounter.ToString
            'ausgabe &= " words."

            'Dim chair As Char = "a"
            'Dim inti As Integer = Asc(chair)


            Doc.Paragraphs(x).Range.Text = ausgabe
        Next

        'Doc.Paragraphs(1).Range.InsertParagraphBefore()
        'Doc.Paragraphs(1).Range.Text = "This text was added by using code."

        'Doc.Paragraphs(1).Range.Sentences.



    End Sub

    'Public Sub AppendFile(ByVal strFile As String, ByVal strOutput As Object)
    '    Dim intFile As Integer
    '    intFile = FreeFile
    '    Microsoft.VisualBasic.Open strFile For Append Access Write As #intFile
    '    Print #intFile, CStr(strOutput)
    '    Close #intFile
    'End Sub

End Class

